home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / BoingBag1 / Contributions / InstallerNG / GUI-API / example / igui_InitApp.c < prev    next >
C/C++ Source or Header  |  1999-10-31  |  20KB  |  403 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. /********************************************************************
  6.  *
  7.  *  DESCRIPTION
  8.  *
  9.  *  allocate memory for the base structure and return it;
  10.  *  additionally set up the window and, if you want to,
  11.  *  a gauge for showing the completion of the parsing process
  12.  *
  13.  *  IN:  texts - a pointer to an array of localized stringpointers
  14.  *               (see the gui.h include for the text offsets)
  15.  *       title - pointer to the window- and screentitle for the
  16.  *               installer gui
  17.  *       globalenv - the global installation environment; things
  18.  *                   like "MINUSER", "LOGFILE" etc are stored
  19.  *                   here
  20.  *
  21.  *  OUT: a private pointer to an application structure or NULL
  22.  *       if something went wrong
  23.  *
  24.  */
  25.  
  26. /********************************************************************
  27.  *
  28.  *  STATIC
  29.  *
  30.  */
  31.  
  32. static void __asm __saveds gui_BTMKDirProceedFun(register __a2 APTR, register __a1 LONG *);
  33. static void __saveds gui_SendCtrlCFun(void);
  34. static void __saveds gui_SendCtrlDFun(void);
  35. static void __saveds gui_SendCtrlEFun(void);
  36.  
  37. static const struct Hook gui_bt_mkdirproceed_hook = { { NULL, NULL }, (VOID *) gui_BTMKDirProceedFun, NULL, NULL };
  38. static const struct Hook gui_bt_closewin_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlCFun, NULL, NULL };
  39. static const struct Hook gui_bt_proceed_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlDFun, NULL, NULL };
  40. static const struct Hook gui_bt_abort_hook = { { NULL, NULL }, (VOID *) gui_SendCtrlEFun, NULL, NULL };
  41.  
  42. /********************************************************************
  43.  *
  44.  *  EXTERN
  45.  *
  46.  */
  47.  
  48. /********************************************************************
  49.  *
  50.  *  PUBLIC
  51.  *
  52.  */
  53.  
  54. /********************************************************************
  55.  *
  56.  *  CODE
  57.  *
  58.  */
  59.  
  60. APTR __asm igui_InitApp(register __a0 char **texts,
  61.                         register __a1 char *title,
  62.                         register __a2 ULONG *globalenv)
  63.  
  64. {
  65.   #ifdef DEBUG
  66.   DEBUG_MAKRO
  67.   #endif
  68.  
  69.   {
  70.     struct Application *app = NULL;
  71.  
  72.     // since this gui works with MUI, we have to open the muimaster lib here
  73.     // (if it's not yet open :-)
  74.     if (!MUIMasterBase) { MUIMasterBase = OpenLibrary("muimaster.library", 19); }
  75.     if (MUIMasterBase)
  76.     {
  77.       // allocate memory for the application-structure
  78.       if (app = AllocVec(sizeof(struct Application), MEMF_ANY|MEMF_CLEAR))
  79.       {
  80.         // temporary store the references to different mui-objects, such that
  81.         // they can be bind together with hooks later
  82.         APTR WI_about, WI_help, WI_aboutmui;
  83.         APTR BT_openabout, BT_endabout, BT_openhelp, BT_endhelp, BT_proceed, BT_abort,
  84.              BT_mkdir_proceed, BT_mkdir_cancel;
  85.         APTR ST_mkdir_name;
  86.         APTR CM_mkdir_info;
  87.         APTR MN_menu, MN_about, MN_aboutmui, MN_quit;
  88.  
  89.         // keep the arguments
  90.         app->app_Texts = texts;
  91.         app->app_Title = title;
  92.         app->app_GlobalEnv = globalenv;
  93.  
  94.         // initially, no error occured yet
  95.         app->app_Error = GUIERROR_NOERROR;
  96.  
  97.         // create the
  98.         app->app_Application = ApplicationObject,
  99.                                  MUIA_Application_Title,       "InstallerNG",
  100.                                  MUIA_Application_Version,     app->app_Title,
  101.                                  MUIA_Application_Copyright,   "(c) 1997-1999 by Jens Tröger",
  102.                                  MUIA_Application_Author,      "Jens Tröger",
  103.                                  MUIA_Application_Description, "InstallerNG with MUI-GUI",
  104.                                  MUIA_Application_Base,        "INSTALLER-NG",
  105.  
  106.                                  // this gui gets its own menu (not a must)
  107.                                  MUIA_Application_Menustrip, MN_menu = MenustripObject,
  108.                                    MUIA_Family_Child, MenuObject,
  109.                                      MUIA_Menu_Title, app->app_Texts[MENU_PROJECT],
  110.                                      MUIA_Family_Child, MN_about = MenuitemObject,
  111.                                        MUIA_Menuitem_Title, app->app_Texts[MENU_ABOUT],
  112.                                        MUIA_Menuitem_Shortcut, "A",
  113.                                      End,
  114.                                      MUIA_Family_Child, MN_aboutmui = MenuitemObject,
  115.                                        MUIA_Menuitem_Title, app->app_Texts[MENU_ABOUTGUI],
  116.                                        MUIA_Menuitem_Shortcut, "G",
  117.                                      End,
  118.                                      MUIA_Family_Child, MUI_MakeObject(MUIO_Menuitem, NM_BARLABEL, 0, 0, 0),
  119.                                      MUIA_Family_Child, MN_quit = MenuitemObject,
  120.                                        MUIA_Menuitem_Title, app->app_Texts[MENU_QUIT],
  121.                                        MUIA_Menuitem_Shortcut, "Q",
  122.                                      End,
  123.                                      End,
  124.                                  End,
  125.  
  126.                                  // the window which contains information about the installer itself
  127.                                  SubWindow, WI_about = WindowObject,
  128.                                    MUIA_Window_Title, app->app_Title,
  129.                                    MUIA_Window_ID, MAKE_ID('1', 'W', 'I', 'N'),
  130.                                    WindowContents, GroupObject,
  131.                                      Child, GroupObject,
  132.                                        //MUIA_Frame, MUIV_Frame_Group,
  133.                                        Child, TextObject,
  134.                                          MUIA_Background, MUII_TextBack,
  135.                                          MUIA_Frame, MUIV_Frame_Text,
  136.                                          MUIA_Text_Contents, app->app_Texts[ABOUT],
  137.                                          MUIA_Text_PreParse, "\33c",
  138.                                        End,
  139.                                        Child, BT_endabout = SimpleButton(app->app_Texts[INTERESTING]),
  140.                                      End,
  141.                                    End,
  142.                                  End,
  143.  
  144.                                  // the help window
  145.                                  SubWindow, WI_help = WindowObject,
  146.                                    MUIA_Window_Title, app->app_Title,
  147.                                    MUIA_Window_ID, MAKE_ID('2', 'W', 'I', 'N'),
  148.                                    WindowContents, GroupObject,
  149.                                      Child, GroupObject,
  150.                                        //MUIA_Frame, MUIV_Frame_Group,
  151.                                        Child, ListviewObject,
  152.                                          MUIA_Listview_Input, FALSE,
  153.                                          MUIA_Listview_List, app->app_HelpText = FloattextObject,
  154.                                            MUIA_Frame, MUIV_Frame_ReadList,
  155.                                            MUIA_Background, MUII_ReadListBack,
  156.                                            MUIA_Floattext_TabSize, 4,
  157.                                            MUIA_Floattext_Justify, TRUE,
  158.                                          End,
  159.                                        End,
  160.                                        Child, BT_endhelp = SimpleButton(app->app_Texts[THANX]),
  161.                                      End,
  162.                                    End,
  163.                                  End,
  164.  
  165.                                  // information about MUI
  166.                                  SubWindow, WI_aboutmui = AboutmuiObject,
  167.  
  168.                                  End,
  169.  
  170.                                  // the Makedir window is required by "AskFile" and "AskDir"
  171.                                  // function to provide tha ability to create a new drawer
  172.                                  SubWindow, app->app_MkdirWindow = WindowObject,
  173.                                     MUIA_Window_Title, app->app_Title,
  174.                                     MUIA_Window_ID, MAKE_ID('3', 'W', 'I', 'N'),
  175.                                     MUIA_Window_NoMenus, TRUE,
  176.                                     WindowContents, GroupObject,
  177.                                       Child, GroupObject,
  178.                                         MUIA_Background, MUII_BACKGROUND,
  179.                                         MUIA_Frame, MUIV_Frame_Group,
  180.                                         Child, TextObject,
  181.                                           MUIA_Background, MUII_TextBack,
  182.                                           MUIA_Frame, MUIV_Frame_Text,
  183.                                           MUIA_Text_Contents, app->app_Texts[MKDIR_PROMPT],
  184.                                           MUIA_Text_SetMin, TRUE,
  185.                                           MUIA_Text_PreParse, "\33c",
  186.                                         End,
  187.                                         Child, GroupObject,
  188.                                           MUIA_Group_Horiz, TRUE,
  189.                                           Child, HVSpace,
  190.                                           Child, GroupObject,
  191.                                             MUIA_Group_Columns, 2,
  192.                                             Child, Label2(app->app_Texts[MKDIR_INFO]),
  193.                                             Child, CM_mkdir_info = CheckMark(FALSE),
  194.                                           End,
  195.                                           Child, HVSpace,
  196.                                         End,
  197.                                         Child, GroupObject,
  198.                                           MUIA_Group_Columns, 2,
  199.                                           Child, Label2(app->app_Texts[MKDIR_ASKNAME]),
  200.                                           Child, app->app_MkdirName = ST_mkdir_name = StringObject,
  201.                                             MUIA_Frame, MUIV_Frame_String,
  202.                                           End,
  203.                                         End,
  204.                                       End,
  205.                                       Child, GroupObject,
  206.                                         MUIA_Group_Horiz, TRUE,
  207.                                         Child, BT_mkdir_proceed = SimpleButton(app->app_Texts[OK]),
  208.                                         Child, BT_mkdir_cancel = SimpleButton(app->app_Texts[BUTTON_CANCEL]),
  209.                                       End,
  210.                                     End,
  211.                                   End,
  212.  
  213.                                  // the window for showing the copy-gauge
  214.                                  SubWindow, app->app_GaugeWindow = WindowObject,
  215.                                     MUIA_Window_ID, MAKE_ID('4', 'W', 'I', 'N'),
  216.                                     MUIA_Window_CloseGadget, FALSE,
  217.                                     MUIA_Window_Width, MUIV_Window_Width_Visible(50),
  218.                                     WindowContents, GroupObject,
  219.                                       Child, GroupObject,
  220.                                         MUIA_Background, MUII_BACKGROUND,
  221.                                         MUIA_Frame, MUIV_Frame_Group,
  222.                                         Child, HVSpace,
  223.                                         Child, app->app_GaugeSrc = TextObject,
  224.                                           MUIA_Background, MUII_TextBack,
  225.                                           MUIA_Frame, MUIV_Frame_Text,
  226.                                           MUIA_FrameTitle, app->app_Texts[SOURCEFILE],
  227.                                           MUIA_Text_Contents, NULL,
  228.                                           MUIA_Text_SetMin, TRUE,
  229.                                         End,
  230.                                         Child, app->app_GaugeDest = TextObject,
  231.                                           MUIA_Background, MUII_TextBack,
  232.                                           MUIA_Frame, MUIV_Frame_Text,
  233.                                           MUIA_FrameTitle, app->app_Texts[DESTFILE],
  234.                                           MUIA_Text_Contents, NULL,
  235.                                           MUIA_Text_SetMin, TRUE,
  236.                                         End,
  237.                                         Child, HVSpace,
  238.                                         Child, app->app_GaugeGauge = GaugeObject,
  239.                                           GaugeFrame,
  240.                                           MUIA_FixHeight, 10,
  241.                                           MUIA_Gauge_Horiz, TRUE,
  242.                                           MUIA_Gauge_Max, 100,
  243.                                         End,
  244.                                         Child, ScaleObject,
  245.                                           MUIA_Scale_Horiz, TRUE,
  246.                                         End,
  247.                                         Child, HVSpace,
  248.                                       End,
  249.                                     End,
  250.                                   End,
  251.  
  252.                                  // this is the main installer window
  253.                                  SubWindow, app->app_MainWindow = WindowObject,
  254.                                    MUIA_Window_Title, app->app_Title,
  255.                                    MUIA_Window_ScreenTitle, app->app_Title,
  256.                                    MUIA_Window_ID, MAKE_ID('0','W','I','N'),
  257.                                    WindowContents, VGroup,
  258.                                      Child, app->app_MainRoot = VGroup,
  259.                                        MUIA_Frame, MUIV_Frame_Group,
  260.                                        MUIA_Background, MUII_RegisterBack,
  261.                                        Child, app->app_CurrentObject = VGroup,
  262.                                          Child, HVSpace,
  263.                                          Child, TextObject,
  264.                                            MUIA_Frame, MUIV_Frame_None,
  265.                                            MUIA_Text_Contents, app->app_Texts[WELCOME],
  266.                                            MUIA_Text_SetMin, TRUE,
  267.                                            MUIA_Text_PreParse, "\33c",
  268.                                          End,
  269.                                          Child, app->app_ParseGauge = GaugeObject,
  270.                                            GaugeFrame,
  271.                                            MUIA_Gauge_Horiz, TRUE,
  272.                                            MUIA_Gauge_InfoText, "%ld %%",
  273.                                            MUIA_Gauge_Max, 100,
  274.                                          End,
  275.                                          Child, HVSpace,
  276.                                        End,
  277.                                      End,
  278.                                      Child, HGroup,
  279.                                        MUIA_Group_Columns, 2,
  280.                                        Child, app->app_ButtonProceed = BT_proceed = SimpleButton((char *) app->app_GlobalEnv[GENV_PROCEED_BUTTON]),
  281.                                        Child, app->app_ButtonCancel = BT_abort = SimpleButton((char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]),
  282.                                        Child, BT_openabout = SimpleButton(app->app_Texts[BUTTON_ABOUT]),
  283.                                        Child, BT_openhelp = SimpleButton(app->app_Texts[BUTTON_HELP]),
  284.                                      End,
  285.                                    End,
  286.                                  End,
  287.                                End;
  288.  
  289.         if (app->app_Application)
  290.         {
  291.           // join the different mui objects, such that they communicate
  292.           // via notifies
  293.  
  294.           DoMethod(app->app_MainWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  295.                    MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_closewin_hook);
  296.  
  297.           //
  298.           DoMethod(BT_proceed, MUIM_Notify, MUIA_Pressed, FALSE,
  299.                    MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_proceed_hook);
  300.           DoMethod(BT_abort, MUIM_Notify, MUIA_Pressed, FALSE,
  301.                    MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_abort_hook);
  302.  
  303.           //
  304.           DoMethod(BT_openabout, MUIM_Notify, MUIA_Pressed, FALSE,
  305.                    WI_about, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  306.           DoMethod(BT_endabout, MUIM_Notify, MUIA_Pressed, FALSE,
  307.                    WI_about, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  308.           DoMethod(WI_about, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  309.                    MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  310.  
  311.           //
  312.           DoMethod(BT_openhelp, MUIM_Notify, MUIA_Pressed, FALSE,
  313.                    WI_help, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  314.           DoMethod(BT_endhelp, MUIM_Notify, MUIA_Pressed, FALSE,
  315.                    WI_help, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  316.           DoMethod(WI_help, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  317.                    MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  318.  
  319.           //
  320.           DoMethod(BT_mkdir_cancel, MUIM_Notify, MUIA_Pressed, FALSE,
  321.                    app->app_MkdirWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  322.           DoMethod(BT_mkdir_cancel, MUIM_Notify, MUIA_Pressed, FALSE,
  323.                    app->app_MainWindow, 3, MUIM_Set, MUIA_Window_Sleep, FALSE);
  324.           DoMethod(app->app_MkdirWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  325.                    app->app_MkdirWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  326.           DoMethod(app->app_MkdirWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  327.                    app->app_MainWindow, 3, MUIM_Set, MUIA_Window_Sleep, FALSE);
  328.           DoMethod(BT_mkdir_proceed, MUIM_Notify, MUIA_Pressed, FALSE,
  329.                    app->app_MainWindow, 5, MUIM_CallHook, &gui_bt_mkdirproceed_hook, ST_mkdir_name, CM_mkdir_info, app);
  330.  
  331.           //
  332.           DoMethod(MN_about, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  333.                    WI_about, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  334.           DoMethod(MN_aboutmui, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  335.                    WI_aboutmui, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  336.           DoMethod(MN_quit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  337.                    MUIV_Notify_Self, 2, MUIM_CallHook, &gui_bt_closewin_hook);
  338.  
  339.           //
  340.           DoMethod(WI_aboutmui, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  341.                    MUIV_Notify_Self, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  342.  
  343.           //
  344.           set(app->app_MainWindow, MUIA_Window_Open, TRUE);
  345.           
  346.           // sleep
  347.           guistuff_SleepApp(app);
  348.  
  349.           // done
  350.           return (app);
  351.         }
  352.       }
  353.     }
  354.  
  355.     // an error has occured, so we have to free all allocated resources
  356.     igui_FreeApp(app);
  357.     return (NULL);
  358.   }
  359. }
  360.  
  361. /********************************************************************/
  362.  
  363. static void __saveds gui_SendCtrlCFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_C); }
  364. static void __saveds gui_SendCtrlDFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_D); }
  365. static void __saveds gui_SendCtrlEFun(void) { Signal(FindTask(NULL), SIGBREAKF_CTRL_E); }
  366.  
  367. static void __asm __saveds gui_BTMKDirProceedFun(register __a2 APTR obj, register __a1 LONG *data)
  368. {
  369.   struct Application *app = (struct Application *) data[2];
  370.   long path, icon;
  371.  
  372.   GetAttr(MUIA_String_Contents, (APTR) data[0], (ULONG *) &path);  // inhalt des string
  373.   GetAttr(MUIA_Selected, (APTR) data[1], (ULONG *) &icon);
  374.  
  375.   // create the new directory
  376.   {
  377.     BPTR newdir = sav_MakeDir((char *) path);
  378.  
  379.     if (newdir)
  380.     {
  381.       UnLock(newdir);
  382.  
  383.       // do wee need to create an icon for the new drawer?
  384.       if (icon)
  385.       {
  386.         struct DiskObject *drawer_obj = GetDefDiskObject(WBDRAWER);
  387.         if (drawer_obj)
  388.         {
  389.           PutDiskObject((STRPTR) path, drawer_obj);
  390.           FreeDiskObject(drawer_obj);
  391.         }
  392.         else { /* unable to create the icon, but that doesn't matter */ }
  393.       }
  394.     }
  395.     else { /* failed to create the new directory */ DisplayBeep(NULL); }
  396.   }
  397.  
  398.   // done... so cleanup
  399.   set(app->app_MainWindow, MUIA_Window_Sleep, FALSE);
  400.   set(app->app_MkdirWindow, MUIA_Window_Open, FALSE);
  401.   set(app->app_MkdirRelatedDirlist, MUIA_Dirlist_Directory, path);
  402. }
  403.